import ajax from '@/utils/request'
// 文章详情页
const getArticleDetailAPI = ({ artId }) => {
  return ajax({
    method: 'GET',
    url: `/v1_0/articles/${artId}`
  })
}
// 文章详情页-关注
const followAutAPI = ({ autId }) => {
  return ajax({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: autId
    }
  })
}
// 取关
const unfollowAutAPI = ({ autId }) => {
  return ajax({
    method: 'DELETE',
    url: `/v1_0/user/followings/${autId}`
  })
}

// 喜欢
const likeAPI = ({ artId }) => {
  return ajax({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target: artId
    }
  })
}
// 不喜欢
const disLikeAPI = ({ artId }) => {
  return ajax({
    method: 'DELETE',
    url: `/v1_0/article/likings/${artId}`
  })
}
// 文章详情获取评论列表
const getCommentListAPI = ({ artId, offset, limit = 10 }) => {
  return ajax({
    method: 'GET',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset,
      limit
    }
  })
}
// 喜欢评论
const likeCommentAPI = ({ cmtId }) => {
  return ajax({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target: cmtId
    }
  })
}

// 不喜欢评论
const disLikeCommentAPI = ({ cmtId }) => {
  return ajax({
    method: 'DELETE',
    url: `/v1_0/comment/likings/${cmtId}`
  })
}
// 文章发布评论
const publishCommentAPI = ({ artId, content }) => {
  return ajax({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target: artId,
      content
    }
  })
}

// 导出
export {
  getArticleDetailAPI,
  followAutAPI,
  unfollowAutAPI,
  likeAPI,
  disLikeAPI,
  getCommentListAPI,
  likeCommentAPI,
  disLikeCommentAPI,
  publishCommentAPI
}
